// component/play-btn/index.js
const isurl = require('../../utils/utils.js')
const config = require('../../config')
var app = getApp();
let innerAudioContext = wx.createInnerAudioContext(); //创建音频实例
Component({
    /**
     * 组件的属性列表
     */
 
    properties: {
        isplay:Boolean,
        tabs:String,
        stopmuic:Boolean,
        musicUrl:String,
    },
   
    data:{
        stopmuic:'',
        tabs:"12",
        isplay:'',
        url:'',
        musicUrl:''
    },
   
    // 
    observers:{ //监听数据的更改
        "tabs,isplay,musicUrl,stopmuic"(tabs,isplay,musicUrl,val){
         console.log("musicUrl",musicUrl)
         console.log(isplay,"isplay")
         this.data.tabs=tabs
         this.data.isplay=isplay
         this.data. musicUrl = musicUrl
        //    if(tabs=='venue' &&  isplay){
        //   innerAudioContext.src = musicUrl; 
        //   innerAudioContext.autoplay = true 
        //   innerAudioContext.play(); 
       
        //    }
           console.log(val,"val")
           if(!val){
            console.log("musicUrl",musicUrl)   
            var that = this
            innerAudioContext.src = musicUrl; 
            // innerAudioContext.autoplay = true 
            innerAudioContext.stop() 
            this.data.isplay=false
         
          }
        },
     
      },
  /**
     * 组件的方法列表
     */
methods:{
    musicStart(e){
        var that = this
        console.log(this.data.musicUrl)
        var musicUrl = that.data.musicUrl
        innerAudioContext.src = musicUrl; 
        innerAudioContext.autoplay = true 
     
     if(that.data.isplay){
        console.log("停止")
         innerAudioContext.stop() 

         that.setData({
            isplay:false
         })
     }else{
         console.log("播放")
         innerAudioContext.play(); 
         that.setData({
            isplay:true
         })
     }
    
    
    },
}
 
})
